home *** CD-ROM | disk | FTP | other *** search
- From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
- Message-ID: <4i09ap$35n@mulga.cs.mu.OZ.AU>
- X-Original-Date: 11 Mar 1996 04:14:17 GMT
- Path: in1.uu.net!bounce-back
- Date: 11 Mar 96 04:18:48 GMT
- Approved: fjh@cs.mu.oz.au
- Newsgroups: comp.std.c++
- Subject: Re: extern inlines
- Organization: Comp Sci, University of Melbourne
- References: <smeyersDo1L8o.99t@netcom.com>
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBFAgUBMUOpyeEDnX0m9pzZAQG/3QF/ezVneGt6fPGNgZUIkkvWG+9TJQXxcviJ
- FBVo0AeLrGS3WkTX1LFv4vvPJ33KXQyl
- =Fg6x
-
- smeyers@netcom.com (Scott Meyers) writes:
-
- >I'm a little confused about the meaning of extern inline functions.
- >DWP 7.1.1.4 makes it clear that extern inline functions have external
- >linkage, so I have two questions.
- >
- >1. Suppose this definition occurs in header1.h:
- >
- > extern inline f() { cout << "Hello."; }
- >
- > Further suppose that header1.h is #included by file1.cpp, file2.cpp, and
- > file3.cpp and that, for whatever reason, f is NOT inlined. Which object
- > file will contain the definition of f? My understanding is that only
- > one of them will.
-
- The C++ standard does not define the notion of an "object file".
- Not all implementations use object files. (For example, C++ interpreters
- may just load the source files into memory.)
-
- However, I think typical implementations will place a definition of f()
- in every object file, and then merge them at link time to ensure that
- the final executable only contains one definition of f().
-
- If you want to find out what your particular implementation does, try
- compiling to assembler (often the `-S' compiler option will have this
- effect) and examining the assembler file, or try exaxmining the object
- file (on Unix implementations, you can use the `nm' command to do
- this).
-
- >2. Now suppose there is a second header file header2.h, which contains
- > this definition:
- >
- > extern inline f() { cout << "Goodbye."; } // note that this is
- > // not the same as f above
- >
- > If I link together an object file containing the definition of f
- > from header1.h and another object file containing the definition of
- > f from header2.h, am I correct in assuming that the resulting
- > program violates the one definition rule and that this violation
- > need not be diagnosed?
-
- Yes.
-
- --
- Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh
- fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3
- ---
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-